package socket1;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

/**
 * @classname:SocketClient
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/21 19:19
 * @version: 0.1
 * @since:1.8
 */
public class SocketClient {
    public static void main(String[] args) {
        final String clientName = "client";
        Scanner input = new Scanner(System.in);

        while (true) {
            try {
                Socket socket = new Socket("localhost", 8888);
                DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
                System.out.println(clientName+dataInputStream.readUTF());

                DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
                System.out.println(clientName);
                dataOutputStream.writeUTF(clientName+input.nextLine());

            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
